#include <vector>
#include <iostream>
 
using namespace std;
 
 
class Graphic
{
  public:
    virtual void print() = 0;
};
 
class Ellipse : public Graphic
{
  public:
    void print (){
      cout << "Ellipse \n";
    }
};
 
class CompositeGraphic : public Graphic
{
  public:
 
   void print (){
     const int graphicCount = graphicList_.size();
 
     for ( int i = 0; i < graphicCount; i++ )
     {
       graphicList_[i]->print();
     }
   }
 
   void add (Graphic *aGraphic){
     graphicList_.push_back(aGraphic);
   }
 
  private:
 
   vector<Graphic*>  graphicList_;
};
 
int main()
{
  // Initialize four ellipses
  Ellipse* ellipse1 = new Ellipse();
  Ellipse* ellipse2 = new Ellipse();
  Ellipse* ellipse3 = new Ellipse();
  Ellipse* ellipse4 = new Ellipse();
 
  // Initialize three composite graphics
  CompositeGraphic* graphic  = new CompositeGraphic();
  CompositeGraphic* graphic1 = new CompositeGraphic();
  CompositeGraphic* graphic2 = new CompositeGraphic();
 
  // Composes the graphics
  graphic1->add(ellipse1);
  graphic1->add(ellipse2);
  graphic1->add(ellipse3);
 
  graphic2->add(ellipse4);
 
  graphic->add(graphic1);
  graphic->add(graphic2);
 
  // Prints the complete graphic (four times the string "Ellipse")
  graphic->print();
 
  delete ellipse1, ellipse2, ellipse3, ellipse4;
  delete graphic1, graphic2, graphic;
 
  return 0;
}
